<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/common/jsp/taglibs-nojs-nocss.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<base href="<%=basePath%>"/>

	<script type="text/javascript">
	// Example: obj = findObj("image1");
	function findObj(theObj,theDoc){
		var p,i,foundObj;
		if(!theDoc)
		theDoc=document;
		if((p=theObj.indexOf("?"))>0&&parent.frames.length){
			theDoc=parent.frames[theObj.substring(p+1)].document;
			theObj=theObj.substring(0,p);
		}
		if(!(foundObj=theDoc[theObj])&&theDoc.all)
			foundObj=theDoc.all[theObj];
		for(i=0;!foundObj&&i<theDoc.forms.length;i++)
			foundObj=theDoc.forms[i][theObj];
		for(i=0;!foundObj&&theDoc.layers&&i<theDoc.layers.length;i++)
			foundObj=findObj(theObj,theDoc.layers[i].document);
		if(!foundObj&&document.getElementById)
			foundObj=document.getElementById(theObj);
		return foundObj;
	}
	//添加一个新项目
	//读取最后一行的行号，存放在txtTRLastIndex文本框中行
	function AddSignRow(){
		var txtTRLastIndex=findObj("txtTRLastIndex",document);
		var rowID=parseInt(txtTRLastIndex.value);
		var signFrame=findObj("SignFrame",document);
		var newTR=signFrame.insertRow(signFrame.rows.length);  //添加行
		newTR.id="SignItem"+rowID;
		var newNameTD=newTR.insertCell(0);  //添加列：序号
		newNameTD.innerHTML=newTR.rowIndex.toString();  //添加列内容
		var newNameTD=newTR.insertCell(1);  //添加列:项目名称
		newNameTD.innerHTML="<textarea id='name_chn"+rowID+"' name='listContent["+rowID+"]' class='dialogy_input max_length:2000 required' rows='' cols='' style='width:500px;height:100px;overflow-y:scroll;overflow-x:hidden;margin-left: 8px;' size='50'></textarea>";  //添加列内容
		//var newEmailTD=newTR.insertCell(2);  //添加列:名称缩写
		//newEmailTD.innerHTML="<input name='name_en[]' id='name_en"+rowID+"' class='names' type='text' size='12'/>";  //添加列内容 
		//var newTelTD=newTR.insertCell(3);  //添加列:数据类型
		//newTelTD.innerHTML = "<select name='type[]' id='type" + rowID + "' style='width:80px;' /><option id='op1' value='int'>整数</option><option id='op1' value='float'>小数</option></select>";  //添加列内容
		//var newMobileTD=newTR.insertCell(4);  //添加列:项目属性
		//newMobileTD.innerHTML = "<select name='prop[]' id='prop" + rowID + "' style='width:80px;'><option id='op1' value='main'>主属性</option><option id='op2' value='minor'>次属性</option></select>";  //添加列内容
		var newDeleteTD=newTR.insertCell(2);  //添加列:删除按钮
		newDeleteTD.innerHTML = "<div align='center' style='width:100px'><a href='javascript:void(0);' onclick=\"DeleteSignRow('SignItem" + rowID + "')\">删除</a></div>";  //添加列内容
		txtTRLastIndex.value=(rowID+1).toString();  //将行号推进下一行 
	}
	//删除指定行
	function DeleteSignRow(rowid){
		var signFrame = findObj("SignFrame",document);
		var signItem = findObj(rowid,document);
		var rowIndex = signItem.rowIndex;  //获取将要删除的行的Index
		signFrame.deleteRow(rowIndex);  //删除指定Index的行
		for(i=rowIndex;i<signFrame.rows.length;i++){  //重新排列序号，如果没有序号，这一步省略
			signFrame.rows[i].cells[0].innerHTML = i.toString();
		}
	}
	//清空列表
	function ClearAllSign(){
		if(confirm('确定要清空所有项目吗？')){
			var signFrame = findObj("SignFrame",document);
			var rowscount = signFrame.rows.length;
			for(i=rowscount - 1;i > 0; i--){  //循环删除行,从最后一行往前删除
				signFrame.deleteRow(i);
			}
			var txtTRLastIndex = findObj("txtTRLastIndex",document);  //重置最后行号为1
			txtTRLastIndex.value = "1";
			AddSignRow();  //预添加一行
		}
	}
	function check(){
		var arr = document.getElementsByTagName('INPUT');
		var str = "";
		for(var i=0;i<arr.length;i++){
			if(arr[i].className == 'names'){
				if(arr[i].value==''){
					alert("工作内容不能为空！！");
					arr[i].focus();
					return false;
				}else{
				  	str = str + arr[i].value+"^";
				}
			}
		}
		document.getElementById("myContent").value = str;
	}
	</script>

<div id="pop_up_content">
	<div class="pop_up_title images_1">
		新建工作日志
	</div>
	<div class="pop_up_body">
		<form id="thisForm" action="saveOrUpdatePersonLog.action" method="post">
			<table id="ww">
					<tr align="center">
						<td width="50">序号</td>
						<td width="600">工作内容 <font color='red'>【不能为空且每一项日志字数限制2000字以内】</font></td>
						<td width="150">操作</td>
					</tr>
			</table>
			<div class="wbs_scroll" style="height: 280px">
				<table id="SignFrame" border="0" cellpadding="2" cellspacing="1" style="margin:0px; font-size:14px;">
					<tr align="center">
						<td width="40"></td>
						<td width="300"></td>
						<td width="100"></td>
					</tr>
				</table>
			</div>
			<table>
				<tr>
					<td >
						<input type="button" id="add" name="add" value="添加新项" onclick="AddSignRow();" class="btn" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
						<input type="button" id="clear" name="clear" value="清空" onclick="ClearAllSign();" class="btn" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
						<input type="hidden" id="txtTRLastIndex" name="txtTRLastIndex" value="1"/>
						<input type="hidden" name="personLogVo.user.id" value="<s:property value="#session.user.userId"/>"/>
					</td>
					<td>
						<input type="button" id="thisButton" name="thisButton" value="提交" class="btn" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
						<input type="button" value="取消" class="btn" onclick="hideDialog();" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>
<script type="text/javascript">
/* 表单提交 */
	i.formSubmit("thisButton",	//绑定的按钮id
					  "thisForm" ,   //提交的表单id
					  function(result){
						  	var jsonMsgObj=new JsonMsgObj(result);
							var  msg=jsonMsgObj.getMessage();
						    var codeId=jsonMsgObj.getCodeid();
							var isOk=jsonMsgObj.getIsok();
							if( isOk ){
							    aerouiAlert(msg);
								hideDialog();// 隐藏窗口
								window.location.reload();
							}else{		// 如果编辑失败了
							  JsManageInfoHandleException( result , function(msg , codeId , isOk){
							  		hideDialog();// 隐藏窗口
							   });
						   }
						});
</script>